package stu.aistar.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import stu.aistar.mapper.MovieAllTypesMapper;
import stu.aistar.mapper.MovieTypeMapper;
import stu.aistar.model.pojo.MovieAllTypes;
import stu.aistar.model.pojo.MovieType;
import stu.aistar.service.MovieAllTypesService;

import java.util.List;

@Service
public class MovieAllTypesServiceImpl implements MovieAllTypesService {

    @Autowired
    private MovieAllTypesMapper movieAllTypesMapper;

    @Autowired
    private MovieTypeMapper movieTypeMapper;

    /**
     * 根据id查询该电影的所有电影类型
     * @param id
     * @return
     */
    @Override
    public List<MovieType> findMovieTypes(Integer id) {
        MovieAllTypes movieAllTypes = movieAllTypesMapper.findMovieTypes(id);
        //电影类型id
        String[] types= movieAllTypes.getTypeIds().split(",");
        return movieTypeMapper.findMovieTypeByIds(types);
    }

    /**
     * 存入电影id的电影类型
     * @param typeIds
     * @param movieId
     * @return
     */
    @Override
    public Integer saveMovieTypes(String typeIds, Integer movieId) {
        return movieAllTypesMapper.insertMovieTypes(typeIds,movieId);
    }
}
